package com.bitinstitute.parkapp.plants;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TextView;

import com.bitinstitute.parkapp.R;
import com.bitinstitute.parkapp.helper.ImageLoader;

public class PlantsSingleMenuItemActivity extends Activity {

	// XML node keys
	static final String KEY_NAME = "name";
	static final String KEY_SCI = "sci_name";
	static final String KEY_FAMILY = "family";
	static final String KEY_ORIGIN = "origin";
	static final String KEY_BLOOM = "bloom";
	static final String KEY_PLACE = "place";
	static final String KEY_SIZE = "size";
	static final String KEY_PLACELUISENPARK = "placeLuisenpark";
	static final String KEY_HEADING1 = "heading1";
	static final String KEY_DESC1 = "description1";
	static final String KEY_HEADING2 = "heading2";
	static final String KEY_DESC2 = "description2";
	static final String KEY_HEADING3 = "heading3";
	static final String KEY_DESC3 = "description3";
	static final String KEY_THUMB_URL = "thumb_url";
	


	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
		setContentView(R.layout.plants_single_list_item);

		// getting intent data
		Intent in = getIntent();

		

		// Get XML values from previous intent
		String name = in.getStringExtra(KEY_NAME);
		String sci = in.getStringExtra(KEY_SCI);
		String family = in.getStringExtra(KEY_FAMILY);
		String origin = in.getStringExtra(KEY_ORIGIN);
		String bloom = in.getStringExtra(KEY_BLOOM);
		String place = in.getStringExtra(KEY_PLACE);
		String size = in.getStringExtra(KEY_SIZE);
		String placeLuisenpark = in.getStringExtra(KEY_PLACELUISENPARK);
		String heading1 = in.getStringExtra(KEY_HEADING1);
		String desc1 = in.getStringExtra(KEY_DESC1);
		String heading2 = in.getStringExtra(KEY_HEADING2);
		String desc2 = in.getStringExtra(KEY_DESC2);
		String heading3 = in.getStringExtra(KEY_HEADING3);
		String desc3 = in.getStringExtra(KEY_DESC3);

		// Displaying all values on the screen
		TextView lblName = (TextView) findViewById(R.id.name_label);
		TextView lblSci = (TextView) findViewById(R.id.sci_label);
		TextView lblFamily = (TextView) findViewById(R.id.family_label);
		TextView lblOrigin = (TextView) findViewById(R.id.origin_label);
		TextView lblBloom = (TextView) findViewById(R.id.bloom_label);
		TextView lblPlace = (TextView) findViewById(R.id.place_label);
		TextView lblSize = (TextView) findViewById(R.id.size_label);
		TextView lblPlaceLuisenpark = (TextView) findViewById(R.id.placeLuisenpark_label);
		TextView lblHeading1 = (TextView) findViewById(R.id.heading1_label);
		TextView lblDesc1 = (TextView) findViewById(R.id.desc1_label);
		TextView lblHeading2 = (TextView) findViewById(R.id.heading2_label);
		TextView lblDesc2 = (TextView) findViewById(R.id.desc2_label);
		TextView lblHeading3 = (TextView) findViewById(R.id.heading3_label);
		TextView lblDesc3 = (TextView) findViewById(R.id.desc3_label);

		lblName.setText(name);
		lblSci.setText(sci);
		lblFamily.setText(family);
		lblOrigin.setText(origin);
		lblBloom.setText(bloom);
		lblPlace.setText(place);
		lblSize.setText(size);
		lblPlaceLuisenpark.setText(placeLuisenpark);
		lblHeading1.setText(heading1);
		lblDesc1.setText(desc1);
		lblHeading2.setText(heading2);
		lblDesc2.setText(desc2);
		lblHeading3.setText(heading3);
		lblDesc3.setText(desc3);

		
		// Imageview to show
		ImageView image = (ImageView) findViewById(R.id.header_picture);

		// Image url
		String image_url = in.getStringExtra(KEY_THUMB_URL);

		// ImageLoader class instance
		ImageLoader imgLoader = new ImageLoader(getApplicationContext());

		// url - image url to load
		// image - ImageView
		imgLoader.DisplayImage(image_url, image);
		
		
		
		// Back Button
		findViewById(R.id.btnBack).setOnClickListener(new OnClickListener() {

			public void onClick(View v) {

				dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN,
						KeyEvent.KEYCODE_BACK));

				dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_UP,
						KeyEvent.KEYCODE_BACK));

			}
		});
	}
}
